package com.have.blog.admin.utils;

import com.have.blog.admin.domain.bo.AdminUserDetail;
import com.have.blog.model.models.Admin;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Created By Have
 * 2021/7/18 10:09
 */
public class SecurityUtil {

    public static AdminUserDetail getUserDetail() {
        return (AdminUserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    public static Integer getUserId() {
        AdminUserDetail userDetail = getUserDetail();
        Admin admin = userDetail.getAdmin();
        Integer adminUid = admin.getUid();
        return adminUid;
    }

    public static String getRoleName() {
        AdminUserDetail userDetail = getUserDetail();
        String roleName = userDetail.getRoleName();
        return roleName;
    }

    public static String getUsername() {
        AdminUserDetail userDetail = getUserDetail();
        String username = userDetail.getUsername();
        return username;
    }
}
